from random import randint


def guess(MaxValue=100):
    money = 5000
    round_number = 1
    print(f"欢迎参加猜数字游戏！目标是猜出1-{MaxValue}之间的数字")
    print(f"你初始拥有{money}元，每次猜错扣500元，猜对奖励3000元")

    while True:
        print(f"\n===== 第{round_number}轮游戏 =====")
        value = randint(1, MaxValue)
        current_money = money

        while True:
            try:
                x = int(input("\n请输入猜测的数字："))
            except ValueError:
                print("请输入有效的整数！")
                continue

            if x > value:
                print("数大了")
                current_money -= 500
            elif x < value:
                print("数小了")
                current_money -= 500
            else:
                print(f"恭喜！猜对了，答案就是{value}")
                current_money += 3000
                print(f"你获得了3000元奖励，当前余额：{current_money}元")
                money = current_money

                choice = input("是否继续下一轮游戏？(yes/no): ").strip().lower()
                if choice == "yes":
                    print("你选择了：是")
                    round_number += 1
                    break
                else:
                    print("你选择了：否")
                    print(f"\n游戏结束！你共完成了{round_number}轮游戏，最终余额是：{money}元")
                    return money

            if current_money <= 0:
                print("\n本轮游戏结束！你的金钱已用尽")
                print(f"正确答案是：{value}")
                money = current_money
                choice = input("是否继续下一轮游戏？(yes/no): ").strip().lower()
                if choice == "yes":
                    print("你选择了：是")
                    money = 5000
                    round_number += 1
                    break
                else:
                    print("你选择了：否")
                    print(f"\n游戏结束！你共完成了{round_number}轮游戏，最终余额是：{money}元")
                    return money

            print(f"猜测错误，你还剩{current_money}元")
            print("请继续猜测...")



guess()